package com.example.zhangwei.ui.demo;

import java.util.HashMap;


import com.example.zhangwei.Constants;
import com.example.zhangwei.R;
import com.example.zhangwei.model.DataParcelable;
import com.example.zhangwei.model.DataSerializable;
import com.example.zhangwei.util.BaseActivity;
import com.example.zhangwei.util.MyLogger;
import com.example.zhangwei.util.ToastMaster;
import com.example.zhangwei.widgts.NotificationWidget;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
public class ActivityLiving extends BaseActivity implements View.OnClickListener,View.OnFocusChangeListener{
	
	private TextView mText;
	
	private TextView mText2;
	
	private MyLogger log = MyLogger.getLogger("ActivityLiving");

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (savedInstanceState != null) {
			String key = savedInstanceState.get("saveKey").toString();
			log.e("savedInstanceState.getkey=="+key);
		}			
		log.e(mApplication.TAG);
		setContentView(R.layout.activity_living);
		
		
		
		mText = (TextView)findViewById(R.id.activity_living_text);
		
		mText2 = (TextView)findViewById(R.id.activity_living_text2);
		//获取Parcelable传递 复杂类
		Bundle bundle = getIntent().getExtras();  
		if (bundle != null)
		{
			DataParcelable parcelableData = bundle.getParcelable(Constants.PassDataKey.PARCELABLE);  
			String strValue = "";
			strValue += parcelableData.id + "\n";
			strValue += parcelableData.name + "\n";
			strValue += parcelableData.mapData.get("map") + "\n";
			mText2.setText(strValue);
		}
		
		findViewById(R.id.activity_living_button).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				changeTo(ActivityLiving.class);
			}
		});
		
		findViewById(R.id.activity_living_notification).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				NotificationWidget.getInstance(ActivityLiving.this).setNotification(0);
			}
		});

		setOnClick(this, findViewById(R.id.activity_living_button2));
		setOnClick(this, findViewById(R.id.activity_living_button_toast));
		setOnClick(this, findViewById(R.id.activity_living_button_toast2));
	}
	
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		log.e("----------onRestart-----------");
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		log.e("----------onStart-----------");
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		log.e("----------onResume-----------");
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		log.e("----------onPause-----------");
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		log.e("----------onStop-----------");
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		log.e("----------onDestroy-----------");
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub
		super.onSaveInstanceState(outState);		
		outState.putString("saveKey", "saving");
		log.e("----------onSaveInstanceState-----------");
	}
	
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
		log.e("----------onConfigurationChanged-----------"+ newConfig.orientation);
		if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
			mText.setText(getString(R.string.landscape));
        }else{
        	mText.setText(getString(R.string.portrait));
        }
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.activity_living_button2:
			//Serializable传递 复杂类
			Intent intent = new Intent();
			DataSerializable data = new DataSerializable();
			data.id = 2; 
			data.name = "zhangwei2";
			data.mapData = new HashMap<String, String>();
			data.mapData.put("map", "mapget2");		
			intent.putExtra(Constants.PassDataKey.SERIALIZABLE, data);
			changeTo(ActivityLiving2.class,intent);
			break;
		case R.id.activity_living_button_toast:
			ToastMaster.getInstance().makeText(this, "toast弹框1111111111111", Toast.LENGTH_LONG);
			break;
		case R.id.activity_living_button_toast2:
			showDialogMessage(this, "提示", "是否删除 "+"XXXX",
            		getString(R.string.confirm), getString(R.string.cancel), 2);
			break;
		default:
			break;
		}
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		
	}
	

}
